﻿#include "alert.h"

Alert::Alert(QWidget * parent)
	: QDialog(parent) {
	ui.setupUi(this);
	setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);

	m_isPressed = false;
}

Alert::~Alert() {
}

void Alert::setText(QString text) {
	ui.lblText->setText(text);
}

void Alert::on_pbOK_clicked() {
	Q_EMIT confirmOK();
	close();
}

void Alert::on_pbClose_clicked() {
	close();
}

void Alert::mousePressEvent(QMouseEvent* event) {
	if (event->button() == Qt::LeftButton
		&& ui.widTitle->geometry().contains(event->pos())) {
		m_isPressed = true;
		m_startMovePos = event->globalPos();
	}
}

void Alert::mouseMoveEvent(QMouseEvent* event) {
	if (m_isPressed) {
		QPoint movePoint = event->globalPos() - m_startMovePos;
		QPoint pos = this->pos() + movePoint;
		m_startMovePos = event->globalPos();
		this->move(pos.x(), pos.y());
	}
}

void Alert::mouseReleaseEvent(QMouseEvent* event) {
	m_isPressed = false;
}

void Alert::keyPressEvent(QKeyEvent *event) {
	switch (event->key()) {
	case Qt::Key_Escape:
		break;
	default:
		QDialog::keyPressEvent(event);
	}
}
